diff options
Diffstat (limited to 'app/api/notifications/[id]/read/route.ts')
| -rw-r--r-- | app/api/notifications/[id]/read/route.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/api/notifications/[id]/read/route.ts b/app/api/notifications/[id]/read/route.ts new file mode 100644 index 00000000..ba894fad --- /dev/null +++ b/app/api/notifications/[id]/read/route.ts @@ -0,0 +1,34 @@ +// app/api/notifications/[id]/read/route.ts +import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import { markNotificationAsRead } from '@/lib/notification/service'; + +export async function PATCH( + request: NextRequest, + { params }: { params: { id: string } } +) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); + } + + const notification = await markNotificationAsRead(params.id, session.user.id); + + if (!notification) { + return NextResponse.json( + { error: 'Notification not found' }, + { status: 404 } + ); + } + + return NextResponse.json({ success: true, notification }); + } catch (error) { + console.error('Error marking notification as read:', error); + return NextResponse.json( + { error: 'Failed to mark notification as read' }, + { status: 500 } + ); + } +}
\ No newline at end of file |
